<template>
  <div style="width: 100%">
    <el-dialog
      title="上传整改文件"
      :visible.sync="uploadOpen"
      width="500px"
      append-to-body
    >
      <el-form
        ref="uploadFormRef"
        :model="uploadForm"
        :rules="uploadRules"
        label-width="100px"
      >
        <el-form-item label="整改文件" prop="correctionUrl">
          <file-upload v-model="uploadForm.correctionUrl" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="uploadClose">取消</el-button>
        <el-button type="primary" @click="uploadConfirm">确定</el-button>
      </div>
    </el-dialog>

    <el-table v-loading="loading" :data="infoList">
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="事项类型" align="center" prop="A" />
      <el-table-column
        label="监测异常内容"
        align="center"
        prop="prescriptionContent"
      />
      <el-table-column label="状态" align="center" prop="disposalStatus">
        <template #default="scope">
          <dict-tag
            :options="dict.type.correction_status"
            :value="scope.row.disposalStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="prescriptionTime"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleInfo(scope.row)"
            >查看开药记录</el-button
          >
          <el-button size="mini" type="text" @click="handleUpload(scope.row)"
            >上传整改文件</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!--<pagination
    v-show="total>0"
    :total="total"
    :page.sync="queryParams.pageNum"
    :limit.sync="queryParams.pageSize"
    @pagination="getList"
  />
-->
  </div>
</template>

<script>
import {
  abnormalPrescription,
  abnormalPrescriptionUploadCorrection,
} from "@/api/zhangping/zpMedicalTodo";
export default {
  name: "yskyTable",
  dicts: ["correction_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      infoList: [],
      // 查询参数
      queryParams: {},
      // 表单参数
      uploadOpen: false,
      uploadForm: {
        correctionUrl: null,
      },
      uploadRules: {
        correctionUrl: [{ required: true, message: "请选取", trigger: "blur" }],
      },
    };
  },
  /*props: {
    editVisible: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  watch:{

  },
  computed: {
    show: {
      get () {
        return this.editVisible
      },
      set (val) {
        this.$emit('update:editVisible', val)
      }
    },
  },*/
  created() {
    this.loading = false;
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      abnormalPrescription().then((resp) => {
        this.infoList = resp.data;
        this.loading = false;
      });
    },
    handleInfo(row) {
      //  alert("待做")
      this.$router.push({
        path: "/medical/abnormalPrescription/detail",
        query: { id: row.id },
      });
    },
    handleUpload(row) {
      this.uploadForm = {
        abnormalPrescriptionId: row.id,
        correctionUrl: null,
      };
      this.uploadOpen = true;
    },
    uploadClose() {
      this.uploadOpen = false;
    },
    uploadConfirm() {
      this.$refs["uploadFormRef"].validate((valid) => {
        if (valid) {
          let fileNames = this.uploadForm.correctionUrl
            .split(",")
            .map((item) => {
              console.log(item);
              let names = item.split("/");
              return names[names.length - 1];
            });

          abnormalPrescriptionUploadCorrection({
            ...this.uploadForm,
            correctionFileName: fileNames.join(","),
          }).then((resp) => {
            this.$modal.msgSuccess("上传成功");
            this.getList();
            this.uploadOpen = false;
          });
        }
      });
    },
  },
};
</script>

<style></style>
